﻿using Microsoft.Owin;
using Owin;
using System;
using System.Threading.Tasks;
using System.Web.Http;
using System.Web.Http.Dispatcher;
using Sustainalytics.ESGRatings.Computing.Service.Filters;

namespace Sustainalytics.ESGRatings.Computing.Service
{
    public class Startup
    {
        public void Configuration(IAppBuilder builder)
        {
            var config = new HttpConfiguration();
            config.Filters.Add(new CustomExceptionFilterAttribute());
            config.Services.Replace(typeof(IHttpControllerActivator), new CompositionRoot());

            WebApiConfig.Register(config);
            config.Formatters.XmlFormatter.SupportedMediaTypes.Clear();
            builder.UseWebApi(config);

            config.EnsureInitialized();
        }
    }

    //public class GlobalExceptionMiddleware : OwinMiddleware
    //{
    //    public GlobalExceptionMiddleware(OwinMiddleware next)
    //        : base(next)
    //    {
    //    }

    //    public override async Task Invoke(IOwinContext context)
    //    {
    //        try
    //        {
    //            await this.Next.Invoke(context);
    //        }
    //        catch (Exception exception)
    //        {
    //        }
    //    }
    //}
}